package cn.edu.hunau.oop.day06;

import org.junit.Test;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.*;

/**
 * @author hb
 * @date 2025-08-11 15:08:21
 */
public class LocalDateTest {

    @Test
    public void init(){
        LocalDate now = LocalDate.now();
        //2025-08-11
        System.out.println(now);
        //指定日期
        LocalDate of = LocalDate.of(2025, 9, 11);
        //2025-09-11
        System.out.println(of);
    }

    @Test
    public void parse(){
        LocalDate now = LocalDate.now();

        String v1 = now.format(DateTimeFormatter.ofPattern("yyyy'年'MM'月'dd'日'"));
        //2025年08月11日
        System.out.println(v1);

        String v2="2026/09/01";
        LocalDate date2 = LocalDate.parse(v2, DateTimeFormatter.ofPattern("yyyy/MM/dd"));
        //2026-09-01
        System.out.println(date2);
    }
    @Test
    public void count(){
        //2025-08-11
        LocalDate now = LocalDate.now();
        LocalDate v1 = now.plusDays(10);
        // 2025-08-21
        System.out.println(v1);

        //2026-08-11
        LocalDate v2 = now.plusYears(1);
        System.out.println(v2);

         //在月份的字段上加上3天
        //2025-11-11
        LocalDate v3 = now.plus(3, ChronoUnit.MONTHS);
        System.out.println(v3);

        //2025-09-10
        LocalDate v4 = now.plus(30, ChronoUnit.DAYS);
        System.out.println(v4);


    }

    @Test
    public void testGet(){
        LocalDate now = LocalDate.now();
        int year = now.get(ChronoField.YEAR);
        //2025
        System.out.println(year);
        int monthValue = now.getMonthValue();
        //8
        System.out.println(monthValue);
        int dayOfYear = now.getDayOfYear();
        //223
        System.out.println(dayOfYear);

    }

    @Test
    public void testSet(){
        //2025-08-11
        LocalDate now = LocalDate.now();
        //设置日期为这一年的第200天
        LocalDate v1 = now.withDayOfYear(200);
        //2025-07-19
        System.out.println(v1);
        //2025-08-02
        LocalDate v2 = now.with(ChronoField.DAY_OF_MONTH, 2);
        System.out.println(v2);
    }


    public int parseId(String id){
        //格式校验
        String idRegex="^\\d{17}[0-9Xx]$";
        if(!id.matches(idRegex)){
            throw new RuntimeException("身份证格式不正确");
        }
        //获得日期 430111200208120012
        //解析出身时间
        String birth = id.substring(6, 14);//20020812
        //日期的计算
        //字符串转LocalDate
        LocalDate birthDate=null;//2002-08-12

        //获得现在的时间
        LocalDate now = LocalDate.now();



        return 0;
    }
}
